package com.gzy.cbrsystem.shimian.action;

import java.util.ArrayList;
import java.util.List;

import com.gzy.cbrsystem.insomnia.InsomniaBasicInfo;
import com.gzy.cbrsystem.shimian.dao.CaseBasicInfo;
import com.gzy.cbrsystem.shimian.dao.ShimianBingzhen;
import com.gzy.cbrsystem.shimian.service.CaseReasoning;
import com.gzy.cbrsystem.shimian.action.KeyWordSearch;
import com.gzy.cbrsystem.util.PageBean;
import com.opensymphony.xwork2.ActionSupport;

public class SearchCaseAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected CaseReasoning caseReasoning;
	protected ShimianBingzhen shimianBingzhen;
	protected CaseBasicInfo caseBasicInfo;
	protected List<InsomniaBasicInfo> insomniaBasicInfoList;
	protected String searchmean;
	protected String query;
	protected List<InsomniaBasicInfo> searchResult;
	protected KeyWordSearch keyWordSearch;
	protected String keywordArray[];
	private PageBean pageBean;
	private int page;
	
	public String[] getKeywordArray() {
		return keywordArray;
	}
	public void setKeywordArray(String []keywordArray) {
		this.keywordArray = keywordArray;
	}
	public KeyWordSearch getKeyWordSearch() {
		return keyWordSearch;
	}
	public void setKeyWordSearch(KeyWordSearch keyWordSearch) {
		this.keyWordSearch = keyWordSearch;
	}
	public List<InsomniaBasicInfo> getInsomniaBasicInfoList() {
		return insomniaBasicInfoList;
	}
	public void setInsomniaBasicInfoList(
			List<InsomniaBasicInfo> insomniaBasicInfoList) {
		this.insomniaBasicInfoList = insomniaBasicInfoList;
	}
	public List getSearchResult()
	{
		return this.searchResult;
	}
	public void setSearchResult(List searchResult)
	{
		this.searchResult=searchResult;
	}
	public String getSearchmean() {
		return searchmean;
	}
	public void setSearchmean(String searchmean) {
		this.searchmean = searchmean;
	}
	public String getQuery()
	{
		return this.query;
	}
	public void setQuery(String query)
	{
		this.query=query;
	}
	public void setShimianBingzhen(ShimianBingzhen shimianBingzhen) {
		this.shimianBingzhen = shimianBingzhen;
	}

	public ShimianBingzhen getShimianBingzhen() {
			return this.shimianBingzhen;
	}
	public void setCaseReasoning(CaseReasoning caseReasoning) {
		this.caseReasoning = caseReasoning;
	}

	public CaseReasoning getCaseReasoning() {
		return this.caseReasoning;
	}
	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public String execute()throws Exception{
		/*
		List result=this.getCaseReasoning().search(this.getQuery());
		this.setSearchResult(result);
		*/
		if(getSearchmean().equals("caseId")){
			List tempList = new ArrayList();
			tempList.add((InsomniaBasicInfo)getCaseReasoning().findCaseBasicInfoByID(query));
			setInsomniaBasicInfoList((List)tempList);
		}
		if(getSearchmean().equals("docName")){
			//setInsomniaBasicInfoList((ArrayList<InsomniaBasicInfo>)this.getCaseReasoning().findCaseBasicInfoByDocName(query)); 
			this.pageBean=getCaseReasoning().queryForPage(1,page);
			return SUCCESS;
			
		}
		if(getSearchmean().equals("keyword")){
			for(int i=0;i<keywordArray.length;i++)
				System.out.println(keywordArray[i]);
			/*ArrayList<String> keywordList = new ArrayList<String>();
			for(int i=0;i<this.keywordArray.length;i++)
				keywordList.add(i, this.keywordArray[i]);
			List<String> caseIdList = keyWordSearch.searchAnd(keywordList);
			for(int i=0;i<caseIdList.size();i++)
				insomniaBasicInfoList.set(i,getCaseReasoning().findCaseBasicInfoByID(caseIdList.get(i)));
			*/
			List tempList = new ArrayList();
			tempList.add(getCaseReasoning().findCaseBasicInfoByID("1"));
			tempList.add(getCaseReasoning().findCaseBasicInfoByID("2"));
			setInsomniaBasicInfoList((List)tempList);
		}
		return SUCCESS;
		
	}
}
